<table class="table table-hover">
    <thead>
    <tr>
        @foreach($headers as $filed => $item)
            <th>{{ $item['title'] }}</th>
        @endforeach
    </tr>
    <tr style="color:#f56f9c">
        @foreach($headers as $filed => $item)
            @if($filed == 'report_date')
                <td>TTL</td>
{{--            @elseif($filed == 'os_app')--}}
{{--                <td>{{ intval($total['sessions_app']) == 0 ?  '0%' : round($total['ordered'] / $total['sessions_app'],3) * 100 .'%' }}</td>--}}
            @elseif($filed == 'os_browser')
                <td>{{ intval($total['sessions_browser']) == 0 ?  '0%' : round($total['ordered'] / $total['sessions_browser'],3) * 100 .'%' }}</td>
            @elseif($filed == 'os_total')
                <td>{{ intval($total['sessions_total']) == 0 ?  '0%' : round($total['ordered'] / $total['sessions_total'],3) * 100 .'%' }}</td>
            @elseif($filed == 'ctr')
                <td>{{ intval($total['impressions']) == 0 ? '0%' : round($total['clicks'] / $total['impressions'],3) * 100 .'%' }}</td>
            @elseif($filed == 'cpc')
                <td>{{ intval($total['clicks']) == 0 ? '0%' : round($total['spend'] / $total['clicks'],3) }}</td>
            @elseif($filed == 'tc')
                <td>{{ intval($total['clicks']) == 0 ? '0%' : round($total['total_units'] / $total['clicks'],3) * 100 .'%' }}</td>
            @elseif($filed == 'acos')
                <td>{{ (!$total['total_sales'] || floatval($total['total_sales']) == 0) ? '0%' : round($total['spend'] / $total['total_sales'],3) * 100 .'%' }}</td>
            @elseif($filed == 'spend_os')
                <td>{{ floatval($total['ordered_sales']) == 0 ? '0%' : round($total['spend'] / $total['ordered_sales'],3) * 100 .'%' }}</td>
            @elseif($filed == 'to')
                <td>{{ intval($total['ordered']) == 0 ? '0%' : round($total['total_units'] / $total['ordered'],3) * 100 .'%' }}</td>
            @elseif($filed == 'pos')
                <td>{{ floatval($total['ordered_sales']) == 0 ? '0%' : round($total['profit'] / $total['ordered_sales'],3) * 100 .'%' }}</td>
            @elseif($item['sumField'])
                <td>{{ array_key_exists($filed,$total) ? $total[$filed] : '' }}</td>
            @else
                <td></td>
            @endif
        @endforeach
    </tr>
    </thead>
    <tbody>
        @foreach($paginator as $row)
            <tr>
                <td>{{ $row->report_date }}</td>
                <td>{{ $row->area->area ?? '' }}</td>
                <td>{{ $row->country->country ?? '' }}</td>
                <td>{{ \App\Util\User::getUsernameById($row->seller_id) }}</td>
                <td>{{ $row->classify->title ?? '' }}</td>
                <td>{{ \App\Models\Product\ProductClassify::$_season[$row->classify->season ?? 3] }}</td>
                <td>{{ $row->profit_rate }}</td>
                <td>{{ $row->star }}</td>
                <td>{{ $row->ratings }}</td>
                <td>{{ $row->b_rank }}</td>
                <td>{{ $row->s_rank }}</td>
                <td>{{ $row->sessions_app }}</td>
                <td>{{ $row->sessions_browser }}</td>
                <td>{{ $row->sessions_total }}</td>
                <td>{{ $row->ordered }}</td>
                <td>{{ $row->ordered_r }}</td>
                <td>{{ $row->ordered_sales }}</td>
{{--                <td>{{ intval($row->sessions_app) == 0 ? '0%' : round($row->ordered / $row->sessions_app,3) * 100 .'%' }}</td>--}}
                <td>{{ intval($row->sessions_browser) == 0 ? '0%' : round($row->ordered / $row->sessions_browser,3) * 100 .'%' }}</td>
                <td>{{ intval($row->sessions_total) == 0 ? '0%' : round($row->ordered / $row->sessions_total,3) * 100 .'%' }}</td>
                <td>{{ $row->page_views_app }}</td>
                <td>{{ $row->page_views_browser }}</td>
                <td>{{ $row->page_views_total }}</td>
                <td>{{ $row->impressions }}</td>
                <td>{{ $row->clicks }}</td>
                <td>{{ intval($row->impressions) == 0 ? '0%' : round($row->clicks / $row->impressions,3) * 100 .'%' }}</td>
                <td>{{ $row->spend }}</td>
                <td>{{ $row->total_units }}</td>
                <td>{{ intval($row->clicks) == 0 ? '0%' : round($row->spend / $row->clicks,3)}}</td>
                <td>{{ intval($row->clicks) == 0 ? '0%' : round($row->total_units / $row->clicks,3) * 100 .'%' }}</td>
                <td>{{ $row->total_sales }}</td>
                <td>{{ (!$row->total_sales || floatval($row->total_sales) == 0) ? '0%' : round($row->spend / $row->total_sales,3) * 100 .'%' }}</td>
                <td>{{ (!$row->spend_os || floatval($row->spend_os) == 0) ? '0%' : $row->spend_os * 100 .'%' }}</td>
                <td>{{ intval($row->ordered) == 0 ? '0%' : round($row->total_units / $row->ordered,3) * 100 .'%' }}</td>
                <td>{{ $row->promotion_discount }}</td>
                <td>{{ $row->reimburse }}</td>
                <td>
                    {{ $row->profit }}
                    <button class="btn btn-xs btn-info list-modal" data-id="{{ $row->id }}">验证</button>
                    <button class="btn btn-xs btn-info list-modal-new" data-id="{{ $row->id }}">验证1</button>
                </td>
                <td>{{ (!$row->ordered_sales || floatval($row->ordered_sales) == 0) ? '0%' : round($row->profit / $row->ordered_sales,3) * 100 .'%' }}</td>
            </tr>
        @endforeach
    </tbody>
</table>
<div class="modal fade" id="tempModal" tabindex="-1">
    <div class="modal-dialog" style="width: 80%;">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<div class="modal fade" id="tempModalNew" tabindex="-1">
    <div class="modal-dialog" style="width: 80%;">
        <div class="modal-content">
            <!-- 内容会加载到这里 -->
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<script language="JavaScript" type="text/javascript">
    $(function () {
        $('.list-modal').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            $("#tempModal").modal({
                remote : '/xqc/operation/total-modal?param=' + id + '&action=verifyTotalProfit'
            });
        });
        $("#tempModal").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });

        $('.list-modal-new').on('click', function(e) {
            e.preventDefault();
            var id = $(this).data('id');
            $("#tempModalNew").modal({
                remote : '/xqc/operation/total-modal?param=' + id + '&action=verifyTotalProfitNew'
            });
        });
        $("#tempModalNew").on("hidden.bs.modal", function() {
            $(this).removeData("bs.modal");
            $(this).find(".modal-content").children().remove();
        });
    });
</script>
